/**
 * network_point管理初始化
 */
var NetworkTrainPoints = {
    id: "NetworkTrainPointsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
NetworkTrainPoints.initColumn = function () {
    return [
        {field: 'selectItem', radio: false},
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '员工编号', field: 'empCode', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '员工姓名', field: 'empName', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '用工类型', field: 'laborType', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '人员状态', field: 'personState', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '年度学时', field: 'annualPeriod', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '积分', field: 'annualCredits', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle', sortable: true},
            {title: '积分来源', field: 'integralOrigin', visible: false, align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
NetworkTrainPoints.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        NetworkTrainPoints.seItem = selected[0];
        return true;
    }
};

NetworkTrainPoints.checks = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        NetworkTrainPoints.seItem = selected;
        return true;
    }
};
/**
 * 点击添加network_point
 */
NetworkTrainPoints.openAddNetworkTrainPoints = function () {
    var index = layer.open({
        type: 2,
        title: '添加员工网络积分',
        area: ['850px', '550px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/networkTrainPoints/networkTrainPoints_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看network_point详情
 */
NetworkTrainPoints.openNetworkTrainPointsDetail = function () {
    if (this.check()) {
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        if(selected.length > 1){
            Feng.info("修改只能选择一条数据！");
            return false;
        }
        var index = layer.open({
            type: 2,
            title: '员工网络积分详情',
            area: ['850px', '550px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/networkTrainPoints/networkTrainPoints_update/' + NetworkTrainPoints.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除network_point
 */
NetworkTrainPoints.delete = function () {
    if (this.checks()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/networkTrainPoints/delete", function (data) {
                Feng.success("删除成功!");
                NetworkTrainPoints.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });

            var ids = "";
            for (var i in NetworkTrainPoints.seItem) {
                if (!ids) {
                    ids += NetworkTrainPoints.seItem[i].id;
                } else {
                    ids += "," + NetworkTrainPoints.seItem[i].id;
                }
            }
            ajax.set("networkTrainPointsId", ids);
            ajax.start();
        };
        Feng.confirm("是否删除选中的"+NetworkTrainPoints.seItem.length +"数据？", operation);

    }
};

/**
 * 查询network_point列表
 */
NetworkTrainPoints.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    NetworkTrainPoints.table.refresh({query: queryData});
};

/**
 * 打开导入employee数据页面
 */
NetworkTrainPoints.import = function () {
    var index = layer.open({
        type: 2,
        title: '导入网络培训积分',
        area: ['850px', '550px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/networkTrainPoints/networkTrainPoints_import'
    });
    this.layerIndex = index;
    layer.full(index);
};


NetworkTrainPoints.g_search = function () {
    var index = layer.open({
        type: 2,
        skin: 'layui-layer-molv',
        title: '高级搜索',
        area: ['800px', '300px'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/employee/g_search',
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var queryData = window["layui-layer-iframe" + index].Employee.search2();

            NetworkTrainPoints.table.setQueryParams(queryData);
            NetworkTrainPoints.table.refresh();
            NetworkTrainPoints.table.empty();
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
    this.layerIndex = index;
};

NetworkTrainPoints.export = function(){
    window.open(Feng.ctxPath + '/networkTrainPoints/export',"_parent");
    Feng.success("导出成功!");
};

$(function () {
    var defaultColunms = NetworkTrainPoints.initColumn();
    var table = new BSTable(NetworkTrainPoints.id, "/networkTrainPoints/list", defaultColunms);
    table.setPaginationType("client");
    NetworkTrainPoints.table = table.init();
});
